package com.chx.three.mama.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.widget.ImageView;

/**
 * Created by Hainuo.
 * Data:2015/3/23
 * Email:851714688@qq.com
 */
public class ImageLoadingHandle {

    public static void imageHandle(String url,ImageView imageView){
        //进行内存缓存的检查，如果有图片，直接加载
        ImageCache imageCache = ImageCache.getInstance();
        Bitmap bitmap = imageCache.getImage(url);
        //如果内存中包含图片对象Bitmap那么久直接设置ImageView
        if (bitmap != null) {

            imageView.setImageBitmap(bitmap);

        }else {//不包含缓存，就进行网络的加载

            //Todo 加载本地文件的内容

            FileCache fileCache = FileCache.getInstance();
            byte[] bytes = fileCache.getContent(url);
            if (bytes != null&& bytes.length>0) {
                Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                imageView.setImageBitmap(bmp);
                imageCache.putImage(url, bmp);

            }else {

                //1.开启异步任务
                ImageLoader task = new ImageLoader(imageView);
                task.execute(url);
            }
        }
    }
}
